package com.sfh.cp.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.SpannableString;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sfh.cp.R;
import com.sfh.cp.util.UtilFace;

import crm.sfh.server.entity.EMessage;

/**
 * 功能描述:
 *
 * @date 2018/5/3
 */
public class WidgetPersonLayout extends LinearLayout{

    TextView tvName;
    TextView tvContent;

    public WidgetPersonLayout(Context context) {

        super (context);
        init();
    }

    public WidgetPersonLayout(Context context, @Nullable AttributeSet attrs) {

        super (context, attrs);
        init();
    }

    public WidgetPersonLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {

        super (context, attrs, defStyleAttr);
        init();
    }

     private void init(){

        inflate (getContext (), R.layout.widget_person_layout,this);
         tvName = (TextView) findViewById (R.id.tvName);
         tvContent = (TextView) findViewById (R.id.tvContent);
    }

    public void setData(EMessage msg){
        if (msg == null){
            return;
        }
        this. tvName.setText (msg.getAuthor ().getName ()+":");

        SpannableString spannableString = UtilFace.getEmotionContent(getContext (), this.tvContent, msg.getContent ());
        this.tvContent.setText(spannableString);

    }
}
